<template>
  <div class="outer">
    <header id="hheader">
      增加学院信息
    </header>
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
      <el-form-item label="学院名称" prop="schoolName" label-width="100px">
        <el-input v-model="ruleForm.schoolName"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: "school-add",
  data() {
    return {
      ruleForm: {
        schoolName: '',
      },
      rules: {
        schoolName: [
          {required: true, message: '请输入学院名称', trigger: 'blur'}
        ]
      }
    };

  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$axios.post("/school/add", this.ruleForm,
              {
                headers: {
                  "Authorization": this.$store.getters.getToken
                }
              }).then(res => {
            this.$message({
              message: res.data.message,
              type: "success"
            });
            this.resetForm('ruleForm');
          })
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },

    getSchool() {
      const _this = this;
      this.$axios.get("/school/getAllName?schoolId=" + _this.$store.getters.getUser.schoolId,
          {
            headers: {
              "Authorization": _this.$store.getters.getToken
            }
          }
      ).then(response => {
        var data = response.data.data;
        _this.teachers = data;
      })
    },
    /*getTermList() {
      const _this = this;
      this.$axios.get("/term/getAll?notAll=1",
          {
            headers: {
              "Authorization": _this.$store.getters.getToken
            }
          }
      ).then(response => {
        var data = response.data.data;
        _this.courseTerm = data.list;
        _this.ruleForm.courseTermId = data.this;
      })
    },*/
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  },
  created() {
    this.getSchool();
    // this.getTermList();
  }
}
</script>

<style scoped>

.outer {
  margin: 0 auto;
  align-content: center;
  text-align: center;
  background: #E9EEF3;
}

#hheader{
  font-size: 36px;
  margin: 30px;
}

.demo-ruleForm {
  width: 400px;
  margin: 100px auto;
  text-align: center;
}
</style>